<!-- Buttons to add to the header. -->
<core-navbar-buttons end>
    <button *ngIf="canSearch" ion-button icon-only (click)="showSearch($event)" [attr.aria-label]="'addon.mod_data.search' | translate">
        <ion-icon name="search"></ion-icon>
    </button>
    <core-context-menu>
        <core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item>
        <core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item>
        <core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'fa-newspaper-o'" (action)="gotoBlog($event)"></core-context-menu-item>
        <core-context-menu-item *ngIf="loaded && !(hasOffline || hasOfflineRatings) && isOnline" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
        <core-context-menu-item *ngIf="loaded && (hasOffline || hasOfflineRatings) && isOnline"  [priority]="600" [content]="'core.settings.synchronizenow' | translate" (action)="doRefresh(null, $event, true)" [iconAction]="syncIcon" [closeOnClick]="false"></core-context-menu-item>
        <core-context-menu-item [priority]="500" *ngIf="canAdd" [content]="'addon.mod_data.addentries' | translate" [iconAction]="'add'" (action)="gotoAddEntries($event)"></core-context-menu-item>
        <core-context-menu-item [priority]="400" *ngIf="firstEntry" [content]="'addon.mod_data.single' | translate" [iconAction]="'document'" (action)="gotoEntry(firstEntry)"></core-context-menu-item>
        <core-context-menu-item *ngIf="prefetchStatusIcon" [priority]="300" [content]="prefetchText" (action)="prefetch($event)" [iconAction]="prefetchStatusIcon" [closeOnClick]="false"></core-context-menu-item>
        <core-context-menu-item *ngIf="size" [priority]="200" [content]="'core.removefiles' | translate:{$a: size}" [iconDescription]="'cube'" (action)="removeFiles()" [iconAction]="'trash'"></core-context-menu-item>
    </core-context-menu>
</core-navbar-buttons>

<!-- Content. -->
<core-loading [hideUntil]="loaded" class="core-loading-center">

    <core-course-module-description [description]="description" [component]="component" [componentId]="componentId" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-course-module-description>

    <!-- Data done in offline but not synchronized -->
    <div class="core-warning-card" icon-start *ngIf="hasOffline || hasOfflineRatings">
        <ion-icon name="warning"></ion-icon>
        {{ 'core.hasdatatosync' | translate: {$a: moduleName} }}
    </div>

    <ion-item text-wrap *ngIf="groupInfo && (groupInfo.separateGroups || groupInfo.visibleGroups)">
        <ion-label id="addon-data-groupslabel" *ngIf="groupInfo.separateGroups">{{ 'core.groupsseparate' | translate }}</ion-label>
        <ion-label id="addon-data-groupslabel" *ngIf="groupInfo.visibleGroups">{{ 'core.groupsvisible' | translate }}</ion-label>
        <ion-select [(ngModel)]="selectedGroup" (ionChange)="setGroup(selectedGroup)" aria-labelledby="addon-data-groupslabel" interface="action-sheet">
            <ion-option *ngFor="let groupOpt of groupInfo.groups" [value]="groupOpt.id">{{groupOpt.name}}</ion-option>
        </ion-select>
    </ion-item>

    <div class="core-info-card" icon-start  *ngIf="!access.timeavailable && timeAvailableFrom">
        <ion-icon name="information-circle"></ion-icon>
        {{ 'addon.mod_data.notopenyet' | translate:{$a: timeAvailableFromReadable} }}
    </div>

    <div class="core-info-card" icon-start *ngIf="!access.timeavailable && timeAvailableTo">
        <ion-icon name="information-circle"></ion-icon>
        {{ 'addon.mod_data.expired' | translate:{$a: timeAvailableToReadable} }}
    </div>

    <div class="core-info-card" icon-start *ngIf="access.entrieslefttoview">
        <ion-icon name="information-circle"></ion-icon>
        {{ 'addon.mod_data.entrieslefttoaddtoview' | translate:{$a: {entrieslefttoview: access.entrieslefttoview} } }}
    </div>

    <div class="core-info-card" icon-start *ngIf="access.entrieslefttoadd">
        <ion-icon name="information-circle"></ion-icon>
        {{ 'addon.mod_data.entrieslefttoadd' | translate:{$a: {entriesleft: access.entrieslefttoadd} } }}
    </div>

    <!-- Reset search. -->
    <ng-container *ngIf="search.searching && !isEmpty">
        <ion-item class="item" *ngIf="!foundRecordsData">
            <a (click)="searchReset()">{{ 'addon.mod_data.resetsettings' | translate}}</a>
        </ion-item>

        <div class="core-success-card" *ngIf="foundRecordsData" (click)="searchReset()">
            <p [innerHTML]="'addon.mod_data.foundrecords' | translate:{$a: foundRecordsData}"></p>
        </div>
    </ng-container>

    <div class="addon-data-contents addon-data-entries-{{data.id}} safe-padding-horizontal" *ngIf="!isEmpty">
        <core-style [css]="data.csstemplate" prefix=".addon-data-entries-{{data.id}}"></core-style>

        <core-compile-html [text]="entriesRendered" [jsData]="jsData" [extraImports]="extraImports"></core-compile-html>
    </div>

    <ion-grid *ngIf="search.page > 0 || hasNextPage">
        <ion-row align-items-center>
            <ion-col *ngIf="search.page > 0">
                <button ion-button block outline icon-start (click)="searchEntries(search.page - 1)">
                    <ion-icon name="arrow-back" md="ios-arrow-back"></ion-icon>
                    {{ 'core.previous' | translate }}
                </button>
            </ion-col>
            <ion-col *ngIf="hasNextPage">
                <button ion-button block icon-end (click)="searchEntries(search.page + 1)">
                    {{ 'core.next' | translate }}
                    <ion-icon name="arrow-forward" md="ios-arrow-forward"></ion-icon>
                </button>
            </ion-col>
        </ion-row>
    </ion-grid>

    <core-empty-box *ngIf="isEmpty && !search.searching" icon="archive" [message]="'addon.mod_data.norecords' | translate">
    </core-empty-box>

    <core-empty-box *ngIf="isEmpty && search.searching" icon="archive" [message]="'addon.mod_data.nomatch' | translate" class="core-empty-box-clickable">
        <a (click)="searchReset()">{{ 'addon.mod_data.resetsettings' | translate}}</a>
    </core-empty-box>

</core-loading>

<ion-fab core-fab bottom end *ngIf="canAdd">
    <button ion-fab (click)="gotoAddEntries($event)" [attr.aria-label]="'addon.mod_data.addentries' | translate">
        <ion-icon name="add"></ion-icon>
    </button>
</ion-fab>
